package com.example.administrator.yunniuusedcar.adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.example.administrator.common.ui.BaseAdapterRV;
import com.example.administrator.common.ui.BaseHolderRV;
import com.example.administrator.yunniuusedcar.holder.MainNewInfo_ButtomOnBingdHolder;
import com.example.administrator.yunniuusedcar.holder.Info01NewHeaderHolder;
import com.example.administrator.yunniuusedcar.holder.Info02ActionInfolHolder;

import java.util.List;

/**  咨讯 holder
 * Created by USER2015 on 2017/12/15.
 */

public class MainInfoAdapter extends BaseAdapterRV {        //extends BaseAdapterRV

    public MainInfoAdapter(Context context, List listData) {
        super(context, listData);
    }

    // viewType: 判断用来显示哪一种类型的item布局
    @Override
    public BaseHolderRV createViewHolder(Context context, ViewGroup parent, int viewType) {
        switch (viewType) {
            case ITEM_TYPE_HEADERS:
                return new Info01NewHeaderHolder(context, parent, this);      // 咨讯 当日头条 头部

            case ITEM_TYPE_SHOPLIST:
                return new MainNewInfo_ButtomOnBingdHolder(context, parent, this);    // 咨讯 当日头条 文章列表

            case ITEM_TYPE_INFOR:
          return new Info02ActionInfolHolder(context, parent, this);      //   咨讯  活动咨询

        }

        return null;
    }

    // 列表显示的三种类型
    private static final int ITEM_TYPE_HEADERS = 0;
    private static final int ITEM_TYPE_SHOPLIST = 1;
    private static final int ITEM_TYPE_INFOR = 2;

    // 判断列表项要显示的是哪一种类型
    @Override
    public int getItemViewType(int position) {
        Object bean = getItem(position);
//
        if (bean instanceof Info01NewHeaderHolder) {      // 随机汽车 列表项
            return ITEM_TYPE_HEADERS;
        }
//
        if (bean instanceof MainNewInfo_ButtomOnBingdHolder) {     // 主菜单 列表项
            return ITEM_TYPE_SHOPLIST;
        }

        if (bean instanceof Info02ActionInfolHolder) { // 广告 列表项
            return ITEM_TYPE_INFOR;
        }

        return -1;
    }
}
